Loading estimates for major pollutants and hydrologic inputs to Tampa Bay. Estimates are tons per year and are unique to each major bay segment. All estimates from Janicki Environmental. Source content here.
cols <- qualitative_hcl(length(levs), palette = "Dynamic")
for(lev in seq_along(levs)){
toplo <- tndat %>%
filter(bay_segment %in% !!levs[lev]) %>%
spread(SOURCE, TN_tons)
showleg <- F
if(lev == 1)
showleg <- T
p <- plot_ly(toplo) %>%
add_markers(x = ~YEAR, y = ~NPS, color = I(cols[5]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp5', name = 'NPS') %>%
add_markers(x = ~YEAR, y = ~IPS, color = I(cols[4]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp4', name = 'IPS') %>%
add_markers(x = ~YEAR, y = ~GWS, color = I(cols[3]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp3', name = 'GWS') %>%
add_markers(x = ~YEAR, y = ~DPS, color = I(cols[2]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp2', name = 'DPS') %>%
add_markers(x = ~YEAR, y = ~AD, color = I(cols[1]), stackgroup = 'one', mode = 'none', marker = list(opacity = 0, size = 0),
showlegend = showleg, legendgroup = 'grp1', name = 'AD') %>%
add_annotations(
text = ~unique(bay_segment),
x = 0.5,
y = 1.2,
yref = "paper",
xref = "paper",
xanchor = "middle",
yanchor = "top",
showarrow = FALSE,
font = list(size = 15)
)
if(lev == 3)
p <- p %>%
layout(
yaxis = list(title = 'Total Nitrogen (tons/yr)')
)
if(lev != 3)
p <- p %>%
layout(
yaxis = list(title = NA)
)
nm <- paste0('p', lev)
assign(nm, p)
}
subplot(p1, p2, p3, p4, p5, shareX = T, nrows = length(levs), shareY = F, titleY = T) %>%
layout(
xaxis = list(title = NA, gridcolor = '#FFFFFF'),
barmode = 'stack',
legend = list(title = list(text = 'Source'))
)
totab <- tndat %>%
select(bay_segment, YEAR, SOURCE, TN_tons) %>%
pivot_wider(names_from = SOURCE, values_from = TN_tons) %>%
rowwise() %>%
mutate(Total = sum(AD, DPS , IPS, NPS ,GWS, na.rm = T)) %>%
ungroup()
totab %>%
downloadthis::download_this(
output_name = "TN-load-data",
output_extension = ".csv",
button_label = "Download data",
button_type = "warning",
has_icon = TRUE,
icon = "fa fa-save"
)
sticky_style <- list(position = "sticky", left = 0, background = "#fff", zIndex = 1,
borderRight = "1px solid #eee", fontWeight = 'bold')
tab <- reactable(totab,
groupBy = 'bay_segment',
columns = list(
YEAR = colDef(name = 'Year',
format = colFormat(digits = 0, separators = FALSE),
style = sticky_style,
headerStyle = sticky_style,
footerStyle = sticky_style
),
bay_segment = colDef(name = ''),
Total = colDef(
class = "sticky right-col-1",
headerClass = "sticky right-col-1",
footerClass = "sticky right-col-1"
)
),
defaultColDef = colDef(
footerStyle = list(fontWeight = "bold"),
format = colFormat(digits = 2, separators = TRUE),
resizable = TRUE
)
)
tab